/**
 * Created by zhaoxk on 2016/9/6.
 */

function getDownloadUrl(type,cb){
	var url = ' ',
			uri = 'version/latest?type='+type,
			_api_url = '';
	try{
		_api_url = api_url;
		url = _api_url+uri
	}catch(e){
		url = 'http://192.168.5.250:8082/'+uri
	}
	$.ajax({
		url:url,
		type:'get',
		success:function(data){
			var status = data.head.success;
			if(status){
				var downloadUrl='';
				if(type == 'ios'){
					downloadUrl = data.content.url;
					if(downloadUrl){
						var http = /^http/i,
							hasHttp = http.test(downloadUrl);
						if(!hasHttp){
							downloadUrl = 'http://'+downloadUrl
						}
						if(typeof cb == 'function'){
							cb(downloadUrl)
						}
						return downloadUrl;
					}else{
						if(typeof cb == 'function'){
							cb(false)
						}
						return false
					}
				}else if(type == 'android'){
					downloadUrl = data.content.url;
					if(downloadUrl){
						var _reg = /\/$/,
							re = _reg.test(_api_url),
							newUrl = '';
						if(re){
							newUrl = _api_url.replace(_reg,'')
						}else{
							return
						}
						downloadUrl = newUrl+downloadUrl;
						if(typeof cb == 'function'){
							cb(downloadUrl)
						}
						return downloadUrl
					}else{
						if(typeof cb == 'function'){
							cb(false)
						}
						return false
					}
				}else{
					if(typeof cb == 'function'){
						cb(false)
					}
				}
			}
		},
		error: function(){
			alert('请检查您的网络是否畅通')
		}
	})
}